<?php

class Tolga_Test_Presenter extends Presenter
{
    public function __construct()
    {
        parent::__construct();
        
        $reg = $this->engine->load('Registry');
        $reg->test = 34543;
        
        echo $reg->test;
        
        $config = $this->engine->load('Config');
        $config->load(Config::TYPE_INI, PATH_APP . DS . 'config.ini', 'staging');
        //echo $config->database->params->host;
        
        // XML-RPC
        /*
        $client = new Zend_XmlRpc_Client('http://localhost/framework/?page=Service');
        $test  = $client->getProxy('myservice'); 
        $par1 = Zend_XmlRpc_Value::getXmlRpcValue(6, Zend_XmlRpc_Value::XMLRPC_TYPE_INTEGER);
        $par2 = Zend_XmlRpc_Value::getXmlRpcValue(7, Zend_XmlRpc_Value::XMLRPC_TYPE_INTEGER);
        echo $test->add($par1, $par2);
        echo "<hr>";
        exit;
        $par1 = 6;
        $par2 = 7;
        $result = $client->call('myservice.add', array($par1,$par2));
        echo $result . "<hr>";
        */
        
        // REST
        $client = $this->engine->load('RestClient');
        $client->connect('http://localhost/framework/?page=Service');
       
        $client->sub(8,6);
        $result = $client->get();
        if($result->isSuccess())
        {
            echo $result;
        }else
        {
            echo "aaa";
        }
        
        exit;
        
        $client = new Zend_Rest_Client('http://localhost/framework/?page=Service');
        echo $client->sayHello('Davey', 'Day')->get();
        echo "<hr>";
        echo $client->add(6,8)->get();
        
        /*
        $a = Zend_Locale::getTranslationList('language','en_US');
        foreach($a as $k => $v)
        {
            echo $k . "-" . $v . "<br>";
        }
        */
        $this->registry->set('test', 123);
        echo $this->registry->test;

        
        $this->registry->set('test2', 1234);
        $this->registry->test3 = 'tolga';
        
        
        $this->logger->log($this->debug->dump('test', 'test', false), Log::DEBUG);
        //$this->zendMemoryTest();
        //echo "s";
        
        $lang = array(
            'Example' => 'Örnek',
            'message2' => 'Nachricht2',
            'message3' => 'Nachricht3');
    
        $translate = new Zend_Translate(
        array(
            'adapter' => 'array',
            'content' => $lang,
            'locale'  => 'en'
        )
        );
        //print $translate->_("Example") . "\n";
    }
    
    private function regTest()
    {
    
        $reg = $this->engine->load('Registry');
        echo $reg->test;
    }
    
    private function zendMemoryTest()
    {
        
        $mem1 = memory_get_usage();
        $data1 = array();
        
        for($i = 0; $i < 13000; $i++)
        {
            $data1[$i] = str_repeat('a', 1000);
        }
        $mem2 = memory_get_usage();
        echo 'Used Memory :' . ($mem2-$mem1) . "<hr>";
        
        
        $mem1 = memory_get_usage();
        $backendOptions = array('cache_dir' => PATH_APP . DS . 'tmp'. DS);
        $memManager = $this->engine->load('Memory')->setStorage(Memory::FILE, $backendOptions);
        
        $data = array();
        for($i = 0; $i < 13000; $i++)
        {
            $data[$i] = $memManager->create(str_repeat('a', 1000));
        } 
        
        $mem2 = memory_get_usage();
        echo 'Used Memory with Zend :' . ($mem2-$mem1) . "<hr>";
    }
}

?>